package com.ang.mqtt.controller;

import com.ang.mqtt.geteway.MqttGateway;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class MqttController {

    @Resource
    private MqttGateway iMqttSender;


    /**
     * 发送MQTT消息
     *
     * @param message 消息内容
     * @return 返回
     */
    @PostMapping(value = "/mqtt", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> sendMqtt(@RequestParam(value = "msg") String message) {
        System.out.println("================生产MQTT消息================" + message);
        iMqttSender.sendToMqtt(message);
        return new ResponseEntity<>("OK", HttpStatus.OK);
    }


    /**
     * 发送MQTT消息
     *
     * @param message 消息内容
     * @return 返回
     */
    @PostMapping(value = "/mqtt2", produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<String> sendMqtt2(@RequestParam(value = "msg") String message) {
        System.out.println("================生产MQTT消息================" + message);
        iMqttSender.sendToMqtt("hello", message);
        return new ResponseEntity<>("OK", HttpStatus.OK);
    }
}

